package class202205.demo05.demo05;


import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;

import java.util.Arrays;

class Student implements Comparable<Student>{
    public String name;
    public int age;
    public double score;

    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o) {
      /*  if (this.age > o.age){
            return 1;
        }else if (this.age == o.age){
            return 0;
        }else {
            return -1;
        }*/
        //return this.name.compareTo(o.name);//姓名比较
        //return this.age-o.age;//年龄比较
        return (int) (this.score-o.score);//分数比较
    }
}

public class Test {


    public static void main(String[] args) {
        Student student1 = new Student("zhangsan",98,78.9);

        Student student2 = new Student("lisi",38,18.9);

        System.out.println(student1.compareTo(student2));
    }
    public static void main1(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("zhangsan",98,78.9);
        students[1] = new Student("lisi",38,18.9);
        students[2] = new Student("abc",78,88.9);

        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
    }
}
